package com.lilili.ssh.book.action;

import java.sql.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.lilili.ssh.base.BaseAction;
import com.lilili.ssh.book.model.Book;
import com.lilili.ssh.book.service.BookManager;
import com.lilili.ssh.relation.service.RelationManager;

public class BookAction extends BaseAction{
	@Autowired
	private BookManager bookManager;
	Book book=new Book();
	public Book getBook(){
		return book;
	}
	public void setBook(Book Book){
		this.book=Book;
	}
	
	public String editBook(){
		String id=this.getRequest().getParameter("id");
		if(StringUtils.isNotEmpty(id)){
			book=bookManager.getBook(id);
		}else{
			book.setRegDate(new Date(System.currentTimeMillis()));
		}
		return this.Result("editBook.jsp");
	}
	
	public String addBook(){
		bookManager.saveBook(book);
		this.getRequest().setAttribute("result","数据保存成功！");
		return SUCCESS;
	}
	
	public String delBook() {
        HttpServletRequest request = this.getRequest();
        String idStr = request.getParameter("idStr");
        if (StringUtils.isNotEmpty(idStr)) {
            String [] ids=idStr.split(",");
            for(String s:ids){
            	bookManager.removeBook(s);
            }
        }
        return SUCCESS;
    }

}
